<?php require_once('../Connections/locale.php'); ?>
<?php
$colname_scadenze = "-1";
if (isset($_GET['id_rivista'])) {
  $colname_scadenze = (get_magic_quotes_gpc()) ? $_GET['id_rivista'] : addslashes($_GET['id_rivista']);
}
mysql_select_db($database_locale, $locale);
$query_scadenze = sprintf("SELECT * FROM riviste, abbonati_riviste, abbonati WHERE riviste.id_rivista = %s and abbonati_riviste.id_rivista = riviste.id_rivista and abbonati_riviste.data_scadenza > curdate() and abbonati_riviste.data_scadenza  <= DATE_ADD(CURDATE(), INTERVAL 1 MONTH) and abbonati.id_abbonato = abbonati_riviste.id_abbonato and abbonati.email is not null", $colname_scadenze);
$scadenze = mysql_query($query_scadenze, $locale) or die(mysql_error());
$row_scadenze = mysql_fetch_assoc($scadenze);
$totalRows_scadenze = mysql_num_rows($scadenze);

mysql_select_db($database_locale, $locale);
$query_emails = "SELECT id_email, subject FROM email_predefinite";
$emails = mysql_query($query_emails, $locale) or die(mysql_error());
$row_emails = mysql_fetch_assoc($emails);
$totalRows_emails = mysql_num_rows($emails);

$colname_dati_rivista = "-1";
if (isset($_GET['id_rivista'])) {
  $colname_dati_rivista = (get_magic_quotes_gpc()) ? $_GET['id_rivista'] : addslashes($_GET['id_rivista']);
}
mysql_select_db($database_locale, $locale);
$query_dati_rivista = sprintf("SELECT descrizione FROM riviste WHERE id_rivista = %s", $colname_dati_rivista);
$dati_rivista = mysql_query($query_dati_rivista, $locale) or die(mysql_error());
$row_dati_rivista = mysql_fetch_assoc($dati_rivista);
$totalRows_dati_rivista = mysql_num_rows($dati_rivista);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Untitled Document</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>
<fieldset>
<legend>Elenco scadenze abbonamenti <?php echo $row_dati_rivista['descrizione']; ?></legend>
<body>

<table border="0" id="datatable">
  <tr>
    <td><strong>Nominativo</strong></td>
    <td><strong>Email</strong></td>
    <td><strong>Scadenza</strong></td>
  </tr>
  <?php do { ?>
    <tr>
	   <td><?php echo $row_scadenze['nominativo']; ?></td>
      <td><?php echo $row_scadenze['data_scadenza']; ?></td>
      <td><?php echo $row_scadenze['email']; ?></td>
    </tr>
    <?php } while ($row_scadenze = mysql_fetch_assoc($scadenze)); ?>
</table>
</fieldset>

<form action="invio_emails.php" method="post" name="form1" target="_self" id="form1">
  <p>Seleziona Email:
    <select name="id_email" id="id_email">
      <?php
do {  
?>
      <option value="<?php echo $row_emails['id_email']?>"><?php echo $row_emails['subject']?></option>
      <?php
} while ($row_emails = mysql_fetch_assoc($emails));
  $rows = mysql_num_rows($emails);
  if($rows > 0) {
      mysql_data_seek($emails, 0);
	  $row_emails = mysql_fetch_assoc($emails);
  }
?>
      </select>
    <input name="id_rivista" type="hidden" value="<?php echo $_GET['id_rivista']; ?>" />
    <input type="hidden" name="hiddenField" />
    <input name="query" type="hidden" id="query" value="<?php echo $query_scadenze; ?>" />
  </p>
  <p>
    <label>
    <input type="submit" name="Submit" value="Invia" />
    </label>
</p>
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($scadenze);

mysql_free_result($emails);

mysql_free_result($dati_rivista);
?>
